package com.woniuxy.service.impl;

import com.woniuxy.mapper.StatisticsMapper;
import com.woniuxy.service.StatisticsService;
import com.woniuxy.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author jia
 * @create 2019/9/28
 * @since 1.0.0
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    public StatisticsMapper statisticsMapper;

    @Override
    public List<Map> selectCountByDay(String date) {
        //创建map list
        List<Map> mapList = new ArrayList<>();
        //创建时间格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //当前时间
        //Date date = new Date();
        //转为固定格式
        String preday = date;
        try {
            for (int i = 0; i < 7; i++) {
                Map<String, String> map = new HashMap();
                //获取前一天时间
                preday = DateUtil.getDate(preday);
                //System.out.println(preday);
                //查询当天总收入
                int auctionCount = statisticsMapper.findAuctionCount(preday)+1000;
                //System.out.println(auctionCount);
                //将金额转为string，并存入map
                String dayCount = auctionCount + "";
                map.put("time", preday);
                map.put("count", dayCount);
                //将map存入list列表
                mapList.add(map);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mapList;
    }

    @Override
    public int findAuctionOnline() {

        return statisticsMapper.findAuctionOnline();
    }
}
